use serde::Deserialize;
use std::fs;
use std::io;

/// Represents the configuration for a specific programming language.
#[derive(Deserialize)]
pub struct Config {
    pub include_directories: Vec<String>,
    pub include_files: Vec<String>,
    pub comment_symbol: String,
    pub root_directory: String,
}

/// Represents the common configuration for the project.
#[derive(Deserialize)]
pub struct CommonConfig {
    pub output_file: String,
    pub default_lang: Option<String>,
}

/// Loads the configuration for a specific programming language.
pub fn load_config(language: &str) -> Result<Config, io::Error> {
    let config_path = format!("lang/{}.yml", language);
    let config_content = fs::read_to_string(config_path)?;
    let config: Config = serde_yaml::from_str(&config_content).map_err(|e| {
        io::Error::new(
            io::ErrorKind::InvalidData,
            format!("Failed to parse YAML: {}", e),
        )
    })?;
    Ok(config)
}

/// Loads the common configuration for the project.
pub fn load_common_config() -> Result<CommonConfig, io::Error> {
    let common_config_path = "common.yml";
    let common_config_content = fs::read_to_string(common_config_path)?;
    let common_config: CommonConfig = serde_yaml::from_str(&common_config_content).map_err(|e| {
        io::Error::new(
            io::ErrorKind::InvalidData,
            format!("Failed to parse common YAML: {}", e),
        )
    })?;
    Ok(common_config)
}